/*
  1:歌曲搜索接口
    请求地址:https://autumnfish.cn/search
    请求方法:get
    请求参数:keywords(查询关键字)
    响应内容:歌曲搜索结果

  2:歌曲url获取接口
    请求地址:https://autumnfish.cn/song/url
    请求方法:get
    请求参数:id(歌曲id)
    响应内容:歌曲url地址
  3.歌曲详情获取
    请求地址:https://autumnfish.cn/song/detail
    请求方法:get
    请求参数:ids(歌曲id)
    响应内容:歌曲详情(包括封面信息)
  4.热门评论获取
    请求地址:https://autumnfish.cn/comment/hot?type=0
    请求方法:get
    请求参数:id(歌曲id,地址中的type固定为0)
    响应内容:歌曲的热门评论
  5.mv地址获取
    请求地址:https://autumnfish.cn/mv/url
    请求方法:get
    请求参数:id(mvid,为0表示没有mv)
    响应内容:mv的地址
*/
var app = new Vue({
  el: "#player",
  data: {
    qurey: "",
    musicList: [],
    musicUrl: "",
    musicDetail: "",
    hotComments: [],
    //动画播放
    isPlaying: false,
    //遮罩层显示状态
    isShow: false,
    //mv地址
    mvUrl: "",
  },
  methods: {
    searchMusic: function () {
      var that = this;
      axios.get("https://autumnfish.cn/search?keywords=" + this.qurey).then(
        function (response) {
          //  console.log(response);
          that.musicList = response.data.result.songs;
          //console.log(response.data.result.songs);
        },
        function (err) {}
      );
    },
    musicPlayer: function (musicId) {
      var that = this;
      //歌曲播放
      
      axios.get("https://autumnfish.cn/song/url?id=" + musicId).then(
        function (response) {
        //   console.log(response);
        //   console.log("对应mp3播放地址："+response.data.data[0].url);
        //   that.musicUrl = response.data.data[0].url;
        that.musicUrl="https://music.163.com/song/media/outer/url?id="+musicId+".mp3"
        },
        function (err) {}
      );
      // console.log("播放");
      // console.log();
      //  console.log(musicId);
      //歌曲封面
      https://api.imjad.cn/cloudmusic/?type=detail&id=28012031
      axios.get("https://api.imjad.cn/cloudmusic/?type=detail&id=" + musicId).then(
        function (response) {
        //   console.log(response);
          // console.log("歌曲封面");
          // console.log("歌曲封面："+response.data.songs[0].al.picUrl);
          that.musicDetail = response.data.songs[0].al.picUrl;
        //   console.log(response.data.songs[0].al.picUrl);

        },
        function (err) {}
      );
      //歌曲评论
      axios.get("https://autumnfish.cn/comment/hot?type=0&id=" + musicId).then(
        function (response) {
        //   console.log(response);
          // console.log(reponse.data.hotComments);
          that.hotComments = response.data.hotComments;
        },
        function (err) {}
      );
    },
    play: function () {
      // console.log("play");
      this.isPlaying = true;
    },
    pause: function () {
      // console.log("pause");
      this.isPlaying = false;
    },
    playMv: function (mvid) {
      //形参
      var that = this;
      axios.get("https://autumnfish.cn/mv/url?id=" + mvid).then(
        function (response) {
          //console.log(response);
          //console.log(response.data.data.url);
          that.isShow = true;
          that.mvUrl = response.data.data.url;
          that.isPlaying = false;
        },
        function (err) {}
      );
    },
    //隐藏
    hide: function () {
      this.isShow = false;
      this.mvUrl = "";
    },
  },
});
